﻿<?php
	require_once('conn.php');

	$exec_customer = "select * from customer where 1";
	$result_customer = mysql_query($exec_customer);
	while($row_customer = mysql_fetch_row($result_customer))
	{
		$searchMobileNO=$row_customer[1];
		if(strlen($searchMobileNO)!=11) continue;
		$name_customer = $row_customer[3];
		$query = "SELECT * FROM pairMap WHERE mapIndex='".$row_customer[4]."'";
		$queryresult = mysql_query($query);
		$trans = mysql_fetch_object($queryresult);			
		$sex_customer = $trans->mapName;
		
		$exec_score_total = "select sum(score) from buyRecord where mobileNO='".$searchMobileNO."'";
		$result_score_total = mysql_query($exec_score_total);
		$row_score_total=mysql_fetch_row($result_score_total);	
		$score_total = $row_score_total[0];
		
		// var_dump($score_total);
		$exec_score_used = "select sum(score) from giftRecord where mobileNO='".$searchMobileNO."'";
		//var_dump($exec_score_used);
		$result_score_used = mysql_query($exec_score_used);
		$row_score_used = mysql_fetch_row($result_score_used);
		//var_dump($row_score_used);
		$score_used = $row_score_used[0];
		//var_dump($score_used);
		
		$score_available = $score_total - $score_used;
		
		// var_dump($name_customer);
		// var_dump($sex_customer);
		// var_dump($score_available);

		$url_header_dd="http://wt.chinaweimei.com.cn/apihttp/SMSSend.aspx?user=%B6%A5%B5%E7%D1%DB%BE%B5%D0%D0&pass=734yvu";
		$url_header_xz="http://wt.chinaweimei.com.cn/apihttp/SMSSend.aspx?user=%C9%EE%DB%DA%D6%EC%CE%B0%C9%FA&pass=weisheng";	

		$msg=$name_customer.$sex_customer."，您的S-OPTA眼镜店可用会员积分".$score_available."分，换礼品、抵现金，中秋国庆欢乐优惠不停歇。丰盛町店";
		$msg=mb_convert_encoding($msg, 'gb2312' ,'utf-8');
		$url=$url_header_dd."&context=".$msg."&mobile=".$searchMobileNO;
		//var_dump($url);
		$result = file_get_contents($url);
		echo $result;
		echo '<br>';
	}
	echo '<script language="JavaScript">window.alert("发送成功");</script>'; 
?>